package com.newlink.building.record.adapter

import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.newlink.building.common_base.model.bean.OpenDoorRecordListData
import com.newlink.building.record.R
import com.newlink.building.record.bean.Module_Record_OpenDoorType

/**
 * @author wangyang
 * @date 2022/9/23
 * @description 开门记录的Adapter
 */
class Module_Record_OpenDoorRecordAdapter(data: MutableList<OpenDoorRecordListData>) :
    BaseQuickAdapter<OpenDoorRecordListData, BaseViewHolder>(
        R.layout.item_open_door_record, data
    ), LoadMoreModule {

    init {
        addChildClickViewIds(R.id.iv_preview)
    }

    override fun convert(holder: BaseViewHolder, item: OpenDoorRecordListData) {
        holder.setText(R.id.tv_name, item.devName)
        val showTime = item.optTime.replace("/", "-")
        holder.setText(R.id.tv_time, showTime)
        holder.setText(R.id.tv_mode, context.getString(Module_Record_OpenDoorType.getResIdByCode(item.type)))

        Glide.with(context)
            .load(item.fileUrl)
            .centerCrop()
            .placeholder(R.drawable.default_screenshot)
            .into(holder.getView(R.id.iv_preview))

        if (item.result == 0) {
            //失败
            holder.setTextColor(R.id.tv_status, context.getColor(R.color.red))
            holder.setText(R.id.tv_status, context.getString(R.string.open_door_result_fail))
        } else {
            //成功
            holder.setTextColor(R.id.tv_status, context.getColor(R.color.green))
            holder.setText(R.id.tv_status, context.getString(R.string.open_door_result_success))
        }
    }
}